<?php 
include "./include/conf.php";

$insert_adherent = $pdo->prepare("insert into adherent(id_adherent,nom,prenom,adresse,tel_fixe,tel_port,email,mdp,date_demande,est_webmaster,est_archive,en_attente)
									values ('',:nom,:prenom,:adresse,:tel_fixe,:tel_port,:email,:mdp,:date_demande,:est_webmaster,:est_archive,:en_attente)");

$insert_adherent->execute(array("nom"=>$_POST['nom'],
							"prenom"=>$_POST['prenom'],
							"adresse"=>$_POST['adresse'],
							"tel_fixe"=>$_POST['tel_fixe'],
							"tel_port"=>$_POST['tel_port'],
							"email"=>$_POST['email'],
							"mdp"=>crypt($_POST['mdp'],$_POST['prenom'].".".$_POST['nom']),
							"date_demande"=>date("Y-m-d"),
							"est_webmaster"=>0,
							"est_archive"=>0,
							"en_attente"=>1
						));

$select_id = $pdo->prepare('select max(id_adherent) as id from adherent');
$select_id->execute();
$id_adherent = $select_id->fetch()->id;

/*
 * champ 1 : date de naissance
 * champ 2 : adresse
 * champ 3 : tel_fixe
 * champ 4 : tel_port
 * champ 5 : email
*/

if(isset($_POST['vis_ddn'])) {
	$insert_ddn = $pdo->prepare('insert into anonymat (id_adherent,id_champ) values (?,?)');
	$insert_ddn->execute(array($id_adherent,1));
}

if(isset($_POST['vis_adresse'])){
	$insert_adresse = $pdo->prepare('insert into anonymat (id_adherent,id_champ) values (?,?)');
	$insert_adresse->execute(array($id_adherent,2));
}

if(isset($_POST['vis_tel_fixe'])){
	$insert_tel_fixe = $pdo->prepare('insert into anonymat (id_adherent,id_champ) values (?,?)');
	$insert_tel_fixe->execute(array($id_adherent,3));
}

if(isset($_POST['vis_tel_port'])){
	$insert_tel_port = $pdo->prepare('insert into anonymat (id_adherent,id_champ) values (?,?)');
	$insert_tel_port->execute(array($id_adherent,4));
}

if(isset($_POST['vis_email'])){
	$insert_email = $pdo->prepare('insert into anonymat (id_adherent,id_champ) values (?,?)');
	$insert_email->execute(array($id_adherent,5));
}
header('Location: index.php');
?>